﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web;
using OGS.Contracts;
using OGS.DataAccess;
using OGS.Utility;

namespace OGS.Web.Models.Admin
{
    public class SaveContentModel
    {
        /// <summary>
        /// The ID
        /// </summary>
        public int ID
        {
            get;
            set;
        }

        /// <summary>
        /// The Name
        /// </summary>
        [Display(Name = "Name")]
        [Required(ErrorMessage = "Please enter name.")]
        public string Name
        {
            get;
            set;
        }

        public string Description
        {
            get;
            set;
        }

        /// <summary>
        /// Checks whether the Content Is Active
        /// </summary>
        [Display(Name = "Is Active")]
        public bool IsActive
        {
            get;
            set;
        }

        public bool IsSuccess { get; set; }

        /// <summary>
        /// Get Content Details
        /// </summary>
        /// <param name="ID"></param>
        /// <returns></returns>
        public void GetContentDetails(int ID)
        {
            Content oContent = DAContent.Instance.GetContentDetails(ID);
            this.ID = oContent.ID;
            this.Name = oContent.Name;
            this.Description = oContent.Description;
            this.IsActive = oContent.IsActive;
        }

        /// <summary>
        /// Save Content
        /// </summary>
        public int SaveContent()
        {
            Content oContent = new Content();
            oContent.ID = this.ID;
            oContent.Name = this.Name.Trim();
            oContent.Description = this.Description.Trim();
            oContent.IsActive = this.IsActive;
            oContent.LastModifiedBy = Helper.GetCurrentUserID();
            oContent.LastModifiedDate = DateTime.Now;

            int result = DAContent.Instance.SaveContent(oContent);
            this.ID = oContent.ID;
            return result;

        }
    }
}